import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import router from './router'
import store from './store'
import App from './App.vue'
import { domer } from '@daelui/dogjs/dist/components.js'
import config from './micros/config'
import '@daelui/dogui/dist/css/boost.min.css'
import '@daelui/dogui/dist/css/theme/black.min.css'

Vue.config.productionTip = false

Vue.use(ElementUI)

/**
 * @function 获取document的body元素
*/
domer.getDocBody = function () {
  let doc = this.getDoc()
  return doc.querySelector('#micro-app') || doc.querySelector('[data-sandbox-configuration]') || doc.body
}

// 是否运行态
const isProd = process.env.NODE_ENV === 'production'
const ap = (window.application || {}).dchat || {}
ap.mode = ap[isProd ? 'prod' : 'dev']

// 路径处理
let microPath = ''
if (window.__POWERED_BY_QIANKUN__) {
  microPath = config.microPath
}
Vue.prototype.getMicroPath = function (path) {
  return path.replace('#', '#' + microPath).replace(/\/+/, '/')
}
Vue.prototype.getMicroRoute = function (path) {
  return path.replace(/^\//, '/' + microPath + '/').replace(/\/+/, '/')
}

/* 原始启动代码 */
if (!window.__POWERED_BY_QIANKUN__) {
  new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount('#micro-app')
}

export default {
  Vue, router, store, App
}

export {
  Vue, router, store, App
}